<g:if test="${team}">
<div class="team-members">
	<div class="row">
		<fieldset class="team span10">
			<legend>Team info</legend>
			<div class="team-profile" class="row">
				<span class="span3"><g:if test="${team?.logo}">
						<span class="property-value" aria-labelledby="imagePath-label">
							<img
							src="${request.contextPath}/images/teamLogo/${fieldValue(bean: team, field: "logo")}"
							class="team-image">
						</span>
					</g:if> <g:else>
						<span class="property-value" aria-labelledby="imagePath-label">
							<img src="${request.contextPath}/images/teamLogo/user.png"
							class="team-image">
						</span>
					</g:else>
					</span> 
					
				<span class="span6">
				<div class="team-info">
					<g:if test="${team?.mailGroup}">
						<p class="team-mail">
							<strong>Group Mail: </strong>
							<g:fieldValue bean="${team}" field="mailGroup" />
						</p>
					</g:if>
					<g:if test="${team?.description}">
						<p class="team-description">
							<strong>Description: </strong>
							<g:fieldValue bean="${team}" field="description" />
						</p>
					</g:if>
					<g:if test="${team?.establishedDate}">
						<p>
							<strong>Established Date: </strong>
							<g:formatDate date="${team?.establishedDate}" format="yyyy-MM-dd" />
						</p>
					</g:if>
					<p>
						<strong>Assigned Project:</strong>
						
						<g:if test="${projListInProgress}">
							<g:each status="j" in="${projListInProgress}" var="project">
								${project.projectName}<g:if
									test="${j != projListInProgress.size() - 1 }">,</g:if> 
							</g:each>
						</g:if>
						<g:else>
							<span style="color: red;"> Not assigned!</span>
						</g:else>
					</p>
					<g:form>
						<table>
							<tr>
								<td><g:hiddenField name="teamId" value="${team?.id}" /> <a
									id="ud-team-${team?.id}" href="#"
									class="btn btn-info input-block-level text-left"><i
										class="icon-pencil icon-white" style="text-align: center;"></i>
										Edit</a></td>
								<g:if test="${team?.teamProjects}">
								</g:if>
								<g:else>
									<td><g:actionSubmit
											class="btn btn-info input-block-level text-left "
											action="deleteTeam"
											value="${message(code: 'default.button.delete.label', default: 'Delete')}"
											onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
									</td>
								</g:else>
							</tr>
						</table>
					</g:form>
				</div>
				<div class="info" align="left">

					<p>
						Send email to invite: (each mail is divided by commas; semicolon or a line break)
						<p>
						<g:hiddenField name="teamId" id="teamId" value="${team?.id}" />
						<g:textArea name="txaMemberList" id="txaMemberList" />
						<a class="btn btn-info text-left" id="invite"><i class="icon-envelope-alt"></i> Invite</a>

						<%--		author: Hieu, updated: Huong	--%>
						<script type="text/javascript">
				function validateEmail(email){
					var atpos=email.indexOf("@");
					var dotpos=email.lastIndexOf(".");
					if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
					  {
					  return false;
					  }

					  return true;
				}
				 
				$('#invite').click(function(){
				<%--	Validate email		--%>
					var message="";
					var valid=true;
					var mailList=$('#txaMemberList').val();			
					mailList=mailList.replace(/\n/g,";");
					mailList=mailList.split(";");	
					var request="";
					if(mailList=="") {
						message="Please specify at least one recipient.";
						valid=false;
					}else{
						$.each(mailList, function(index, value) {
							value=value.trim();	
							if(validateEmail(value)==false){					
								valid=false;
								message= "Please make sure that all addresses are properly formed.";
								return false;
							}
							request+=value.trim()+";";							
						});
						request=request.substr(0,request.length-1);		//remove ";" in the end of request string			
					}		

					message="<div style='color: red'>"+message+"</div>";
					$('#sendRedsult').html(message);
					
					if (valid){
						$('#sendRedsult').html("<span class='processing'></span>")
						$.get('${g.createLink(controller:'team',action:'sendMailActive')}',{teamId :$('#selectteam').val() ,txaMemberList: request},function(data){
								$('#sendRedsult').html(data.result);
								
								$.get('${g.createLink(controller:'team',action:'getMember')}',{teamId :$('#selectteam').val()} ,function(data){
									$('#memberDetail').html(data);
								});
						});
					}
			
				});
			</script>
					
					
					
					<div id="sendRedsult"></div>
				</div>
				</span> 
				
				
				
			</div>

		</fieldset>
	</div>
</div>
<div id="memberDetail" class="team-members">
	<g:render template="memberDetail"></g:render>
</div>

</g:if>